import json


def write_config(self, config_file_path):
    """将界面参数写入配置文件"""
    config = {
        "id": self.ui.id.text(),
        "password": self.ui.password.text(),
        "title": self.ui.title.currentText(),
        "covid_test": self.ui.covid_test.currentIndex(),
        "covid_result_index": self.ui.covid_result_index.currentIndex(),
        "covid_test_time": self.ui.covid_test_time.text(),
        "temperature": self.ui.temperature.value(),
        "isolation_index": self.ui.isolation.currentIndex(),
        "code_color_index": self.ui.code_color.currentIndex(),
        "auto_inquire": self.ui.auto_inquire.currentIndex()
    }

    with open(config_file_path, 'w', encoding='utf-8') as f:
        json.dump(config, f, ensure_ascii=False)


def read_config(self, config_file_path):
    """读取配置文件，写入界面参数"""
    with open(config_file_path, 'r', encoding='utf-8') as f:
        config = json.load(f)
    # centerline
    self.ui.id.setText(config["id"])
    self.ui.password.setText(config["password"])
    self.ui.covid_test_time.setText(config["covid_test_time"])

    self.ui.covid_test.setCurrentIndex(config["covid_test"])
    self.ui.isolation.setCurrentIndex(config["isolation_index"])
    self.ui.code_color.setCurrentIndex(config["code_color_index"])
    self.ui.covid_result_index.setCurrentIndex(config["covid_result_index"])
    self.ui.auto_inquire.setCurrentIndex(config["auto_inquire"])

    self.ui.temperature.setValue(config["temperature"])

    self.ui.title.setCurrentText(config["title"])
